package com.yuerlive.rainbow.module.mine.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.common.BaseRecycleViewAdapter;
import com.yuerlive.rainbow.entity.GradleInfo;
import com.yuerlive.rainbow.utils.GlideUtil;
import com.yuerlive.rainbow.widget.CircleImageView;
import com.yuerlive.rainbow.widget.CustomBottomSheetDialog;
import com.yuerlive.rainbow.widget.CustomHorizontalProgressBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Admin on 2017/5/22.
 */

public class GradleAdapter extends BaseRecycleViewAdapter {
    public static final int  HEAD=1;
    public static final int  ITEM=2;
    private List<GradleInfo> infos;
    public GradleAdapter(Context mContext,List<GradleInfo> infos) {
        super(mContext);
        this.infos=infos;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=null;
        RecyclerView.ViewHolder holder=null;
        switch (viewType){
            case HEAD:
                holder=new HeadHolder(mInflater.inflate(R.layout.layout_gradle_head,parent,false));
                break;
            case ITEM:
                holder=new ItemHolder(mInflater.inflate(R.layout.layout_gradle_item,parent,false));
                break;
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      switch (getItemViewType(position)){
          case HEAD:
              setHeadData((HeadHolder) holder, position);
              break;
          case ITEM:
              setItemData((ItemHolder)holder,position);
              break;
      }
    }

    private void setItemData(ItemHolder holder, int position) {
       GradleInfo info=infos.get(position);
        if(info!=null){
            holder.ivIcon.setImageResource(R.drawable.gradle_icon);
            holder.tvLevel.setText("LV.1.开启");
            holder.tvName.setText("等级图标");
        }

    }

    private void setHeadData(HeadHolder holder, int position) {
        GlideUtil.load(mContext,"",holder.civHeader);
        holder.tvGradleNum.setText("20");
        holder.tvUpGradeTip.setText("LV.24");
        holder.tvNextLevel.setText("LV.25");
        holder.pbProgressBar.setProgress(40);
        holder.tvUpGradeTip.setText("距离LV.25还差654经验");
    }

    @Override
    public int getItemCount() {
        if(infos!=null && infos.size()!=0){
            return infos.size();
        }else{
            return 0;
        }
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return  HEAD;
        }else{
            return ITEM;
        }
    }
    static class HeadHolder extends RecyclerView.ViewHolder {
         @BindView(R.id.civHeader)
        CircleImageView civHeader;
        @BindView(R.id.ivGradleIcon)
        ImageView ivGradleIcon;
        @BindView(R.id.tvGradleNum)
        TextView tvGradleNum;
        @BindView(R.id.tvUpLevel)
        TextView tvUpLevel;
        @BindView(R.id.pbProgressBar)
        CustomHorizontalProgressBar pbProgressBar;
        @BindView(R.id.tvNextLevel)
        TextView tvNextLevel;
        @BindView(R.id.tvUpGradeTip)
        TextView tvUpGradeTip;

        public HeadHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    static class ItemHolder extends  RecyclerView.ViewHolder{
        @BindView(R.id.ivIcon)
        ImageView ivIcon;
        @BindView(R.id.tvName)
        TextView tvName;
        @BindView(R.id.tvLevel)
        TextView tvLevel;


        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
